 window.fbAsyncInit = function() {
    FB.init({
      appId      : '357913237611623', // App ID
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
 
   
    // Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

   
/* main entry point */
$(function() {
  setTimeout(hideSplash, 3000);
});


/* hides splash screen */
function hideSplash()
	{
	alert(document.location);
	$.mobile.changePage("#home");
	//
	// facebook stuff
FB.getLoginStatus(function(response) {
 	  if (response.status === 'connected') {
 	    // the user is logged in and has authenticated your
 	    // app, and response.authResponse supplies
 	    // the user's ID, a valid access token, a signed
 	    // request, and the time the access token 
 	    // and signed request each expire
 	    var uid = response.authResponse.userID;
 	    var accessToken = response.authResponse.accessToken;
 	    FB.api('/me', function(response) {
 	    	//$('#AL').simpledialog('open');
			      // alert('Good to see you, ' + response.name + '.');
 	    //	$("#userpic").attr('src', "http://graph.facebook.com/"+response.id+"/picture");
			alert(response.name);
 	    //	$.mobile.changePage( "#two", { transition: "slideup"} );
 	  
			     });
 	   var body = 'Giffoni Experience';
 	  FB.api('/me/feed', 'post', { message: body }, function(response) {
 	    if (!response || response.error) {
 	      alert('Error occured');
 	    } else {
 	      alert('Post ID: ' + response.id);
 	    }
 	  });
 	   // alert('connect');
 	
 	  }
 	 else if (response.status === 'not_authorized') {
    	    // the user is logged in to Facebook, 
    	    // but has not authenticated your app
    		  alert('not authorized');
    		  FB.login(function(response) {
   			   if (response.authResponse) {
   			    // alert('Welcome!  Fetching your information.... ');
   			     FB.api('/me', function(response) {
   			      // alert('Good to see you, ' + response.name + '.');
   			     });
   			   } else {
   			    alert('User cancelled login or did not fully authorize.');
   			   }
   			 }, {scope: 'user_about_me,user_location,user_hometown,publish_stream'});
    	  } else {
    		  
    	    // the user isn't logged in to Facebook.
    		  alert('not logged');
    		  FB.login(function(response) {
    			   if (response.authResponse) {
    				
    			    // alert('Welcome!  Fetching your information.... ');
    			     FB.api('/me', function(response) {
    			    	

    		
    			     });
    			   } else {
    			    alert('User cancelled login or did not fully authorize.');
    			   }
    			 }, {scope: 'user_about_me,user_location,user_hometown,publish_stream'});
    	  }
 	  });
	
	}

function loadMap()
	{
	//alert("loadmap");
	detectBrowser();
	initializeGoogleMap(40.71318, 14.94159); // Giffoni Valle Piana, Salerno, Italy
	$.mobile.changePage("#page_map");
	}

//$("#map_button").click(function (e) {
	//e.stopImmediatePropagation();
	//e.preventDefault();
	//Do important stuff....
//	});

/* live handler on 'map' button */
/*$('#map_button').live('click', function() {
	});*/
